home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4992 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  65 lines

  1. Path: fig.leba.net!not-for-mail
  2. From: fweaver@leba.net
  3. Newsgroups: comp.lang.c
  4. Subject: fopen not working
  5. Date: 10 Feb 1996 22:25:21 -0500
  6. Organization: LebaNet, Lebanon PA
  7. Sender: fweaver@fig.leba.net
  8. Message-ID: <4fjnj1$4q@fig.leba.net>
  9. NNTP-Posting-Host: fig.leba.net
  10.  
  11. Good evening to all C programers
  12.  
  13.    I have a problem I thought someone might be able to shed some light on 
  14. for me. Below is some of the code I wrote for an install program.
  15.  
  16.  
  17. #include<stdio.h>
  18. #include<conio.h>
  19. char buf[125],stwd[110],trwd[110],*pt,*pt1;
  20. int i,vr,vd;
  21. FILE *in, *out;
  22. main()
  23. {   [snip]
  24.  
  25.  instlfile("trkr.cf_","trkr.cfg");
  26.  instlfile("maplvl3.da_","maplvl3.dat");
  27.  instlfile("atpctrkr.do_","atpctrkr.doc");
  28.  instlfile("readme.1s_","readme.1st");
  29.  instlfile("file_id.di_","file_id.diz");
  30.  
  31.  [snip]
  32.  
  33.  if((in=fopen(buf,"r"))!=NULL)
  34.   { do{ fgets(buf,120,in);
  35.    pt= (char *)strstr(buf,"XXXXX");
  36.    if(pt!=NULL){ fclose(out); pt=pt+5;if((out=fopen(pt,"w"))==NULL)printf("ERROR");
  37.  else{printf("\nInstalling %s",pt);continue; }}
  38.    fputs(buf,out);
  39.  }while(feof(in)==0);
  40.  }
  41. }
  42.    What I am trying to do here is seperate one text file (in) back into 
  43. individual files (out). Each file within the first file, starts with a line 
  44. beginning XXXXX. Immediately following (on the same line) is the file name  
  45. for the following lines of text. When XXXXX is found the old out file is to be
  46. closed and a new one fopened. That is not happenning. Pointer pt is pointing
  47. at the correct data, because if I printf("%s",pt); instead printf("ERROR");
  48. it prints the correct file name. File pointer out is still NULL, though after
  49. fopen. The function below works just fine. Any Ideas welcome. Thanks
  50.  
  51. Floyd Weaver
  52.  
  53. Internet E-Mail    fweaver@leba.net
  54. Home page          http://www.leba.net/~fweaver
  55.  
  56.  [snip]
  57.  
  58. instlfile(char f[15],char s[15])
  59. { sprintf(buf,"%s%s",stwd,f);
  60.  if((in=fopen(buf,"rb"))==NULL){close(in);return(0);}
  61.  if((out=fopen(s,"wb"))!=NULL)printf("\nInstalling %s",s);
  62.  while((i=fgetc(in))!=EOF){fputc(i,out);}
  63.  _fcloseall();
  64. }
  65.